package com.interfaces.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

public class ProjectConfig {
    @Component
    public static class WxPayInit{
        public static String APPID;
        //密钥
        public static String SECRET;
        //商户号
        public static String MCHID;
        public static String serialNumber;
        public static String keyPath;
        public static String notifyUrl;
        public static String v3key;
        public static String privateKeyPath;
        public static String privateCertPath;
        public static String pubKeyPath;
        public static String pubKey;
        @Value("${wx.appid}")
        public void setAPPID(String APPID) {
            WxPayInit.APPID = APPID;
        }
        @Value("${wx.secret}")
        public void setSECRET(String SECRET) {
            WxPayInit.SECRET = SECRET;
        }
        @Value("${wx.mchid}")
        public void setMCHID(String MCHID) {
            WxPayInit.MCHID = MCHID;
        }
        @Value("${wx.serialNumber}")
        public void setSerialNumber(String serialNumber) {
            WxPayInit.serialNumber = serialNumber;
        }
        @Value("${wx.keyPath}")
        public void setKeyPath(String keyPath) {
            WxPayInit.keyPath = keyPath;
        }
        @Value("${wx.notifyUrl}")
        public void setNotifyUrl(String notifyUrl) {
            WxPayInit.notifyUrl = notifyUrl;
        }
        @Value("${wx.v3key}")
        public void setV3key(String v3key) {
            WxPayInit.v3key = v3key;
        }
        @Value("${wx.privateKeyPath}")
        public void setPrivateKeyPath(String privateKeyPath) {
            WxPayInit.privateKeyPath = privateKeyPath;
        }
        @Value("${wx.privateCertPath}")
        public void setPrivateCertPath(String privateCertPath) {
            WxPayInit.privateCertPath = privateCertPath;
        }
        @Value("${wx.pubKeyPath}")
        public void setPubKeyPath(String pubKeyPath) {
            WxPayInit.pubKeyPath = pubKeyPath;
        }
        @Value("${wx.pubKey}")
        public void setPubKey(String pubKey) {
            WxPayInit.pubKey = pubKey;
        }
    }
    @Component
    public static class AliPayInit{
        public static String protocol="https";
        public static String gatewayHost="openapi.alipay.com";
        public static String signType="RSA2";
        public static String appId;
        //= "<-- 请填写您的应用私钥，例如：MIIEvQIBADANB ... ... -->"
        public static String merchantPrivateKey;
        //= "<-- 请填写您的应用公钥证书文件路径，例如：/foo/appCertPublicKey_2019051064521003.crt -->"
        public static String merchantCertPath;
        // "<-- 请填写您的支付宝公钥证书文件路径，例如：/foo/alipayCertPublicKey_RSA2.crt -->";
        public static String alipayCertPath;
        //= "<-- 请填写您的支付宝根证书文件路径，例如：/foo/alipayRootCert.crt -->"
        public static String alipayRootCertPath;
        public static String notifyUrl;
        @Value("${Ali.protocol}")
        public void setProtocol(String protocol) {
            AliPayInit.protocol = protocol;
        }
        @Value("${Ali.gatewayHost}")
        public void setGatewayHost(String gatewayHost) {
            AliPayInit.gatewayHost = gatewayHost;
        }
        @Value("${Ali.signType}")
        public void setSignType(String signType) {
            AliPayInit.signType = signType;
        }
        @Value("${Ali.appId}")
        public void setAppId(String appId) {
            AliPayInit.appId = appId;
        }
        @Value("${Ali.merchantPrivateKey}")
        public void setMerchantPrivateKey(String merchantPrivateKey) {
            AliPayInit.merchantPrivateKey = merchantPrivateKey;
        }
        @Value("${Ali.merchantCertPath}")
        public void setMerchantCertPath(String merchantCertPath) {
            AliPayInit.merchantCertPath = merchantCertPath;
        }
        @Value("${Ali.alipayCertPath}")
        public void setAlipayCertPath(String alipayCertPath) {
            AliPayInit.alipayCertPath = alipayCertPath;
        }
        @Value("${Ali.alipayRootCertPath}")
        public void setAlipayRootCertPath(String alipayRootCertPath) {
            AliPayInit.alipayRootCertPath = alipayRootCertPath;
        }
        @Value("${Ali.notifyUrl}")
        public void setNotifyUrl(String notifyUrl) {
            AliPayInit.notifyUrl = notifyUrl;
        }
//        @PostConstruct
//        private static void getOptions() {
//            Config config = new Config();
//            config.protocol = ProjectConfig.AliPayInit.protocol;
//            config.gatewayHost = ProjectConfig.AliPayInit.gatewayHost;
//            config.signType = ProjectConfig.AliPayInit.signType;
//            config.appId = ProjectConfig.AliPayInit.appId;
//            // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
//            config.merchantPrivateKey = ProjectConfig.AliPayInit.merchantPrivateKey;
//            //注：证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径，优先从文件系统中加载，加载失败后会继续尝试从CLASS_PATH中加载
//            config.merchantCertPath = ProjectConfig.AliPayInit.merchantCertPath;
//            config.alipayCertPath = ProjectConfig.AliPayInit.alipayCertPath;
//            config.alipayRootCertPath = ProjectConfig.AliPayInit.alipayRootCertPath;
//            //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
//            // config.alipayPublicKey = "<-- 请填写您的支付宝公钥，例如：MIIBIjANBg... -->";
//            //可设置异步通知接收服务地址（可选）
//            config.notifyUrl = ProjectConfig.AliPayInit.notifyUrl;
//            //可设置AES密钥，调用AES加解密相关接口时需要（可选）
//            // config.encryptKey = "<-- 请填写您的AES密钥，例如：aa4BtZ4tspm2wnXLb1ThQA== -->";
//            Factory.setOptions(config);
//        }
    }


    @Component
    @Order(1)
    public static class BaseConfig{
        public static String qrcode;
        public static String profile;
        @Value("${config.qrcode}")
        public void setQrcode(String qrcode) {
            BaseConfig.qrcode = qrcode;
        }
        @Value("${config.profile}")
        public void setProfile(String profile) {
            BaseConfig.profile = profile;
        }
    }
}
